package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 新增地址
     * @param addressBook
     */
    @Insert("insert into address_book (user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) " +
            "VALUES (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void insertAddress(AddressBook addressBook);

    /**
     * 查询所有地址
     * @param addressBook
     * @return
     */
    List<AddressBook> getAddress(AddressBook addressBook);

    /**
     * 根据id修改地址信息
     * @param addressBook
     */
    void updateById(AddressBook addressBook);

    /**
     * 根据id查询地址信息
     * @param id
     * @return
     */
    @Select("select *from address_book where id=#{id}")
    AddressBook selectById(Long id);

    /**
     * 根据id删除地址
     * @param id
     */
    @Delete("delete from address_book where id=#{id}")
    void deleteAddressById(Long id);

    /**
     * 修改用户所有地址的状态
     * @param addressBook
     */@Update("update address_book set is_default=#{isDefault} where user_id=#{userId}")
    void updateDefault(AddressBook addressBook);
}
